#!/bin/ksh

LOGIN=$1
SH_DIR=$2
SH_FILE=$3
UP_DIR=$4
UP_FILE=$5

sqlplus -s $LOGIN<<!
DELETE FROM ccs.ccs_ams_tmp_supaging;
COMMIT;
!

cat > $UP_DIR/ctl/$SH_FILE.ctl<<!
LOAD DATA
INFILE '$UP_DIR/$UP_FILE'
APPEND INTO TABLE CCS.CCS_AMS_TMP_SUPAGING
FIELDS TERMINATED BY ';'
TRAILING NULLCOLS
(
AGING_GROUP,
SUP_ACCOUNT_NO,
UB_ACCOUNT_NO,
UB_BU_TYPE, 
BILL_CYCLE,
NETWORK,
MOBILE_NO,
CUSTOMER_CLASS,
ACCOUNT_NAME,
UNAGE_BALANCE,
DAY_00_BALANCE,
DAY_30_BALANCE,
DAY_60_BALANCE,
DAY_90_BALANCE,
TOTAL_BALANCE,
LAST_PYMT_DATE DATE "dd/mm/yyyy" 
)
!
/usr/local/bin/dos2unix $UP_DIR/$UP_FILE
sqlldr $LOGIN \
control=$UP_DIR/ctl/$SH_FILE.ctl bad=$UP_DIR/bad/$SH_FILE.bad \
log=$UP_DIR/log/$SH_FILE.log >> $UP_DIR/log/$SH_FILE.log
